package  com.syqc.sensor

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.syqc.entity.ListInfo
import com.syqc.monitor.R
import com.syqc.utils.ToolsUtil
import com.syqc.utils.Units
import kotlin.math.abs

/**
 *@Author pc_hfjs
 *@Date 2022/2/12 9:55
 *@Desc
 */
class AddLeakAdapter(private val unit: String) :
    BaseQuickAdapter<ListInfo, BaseViewHolder>(R.layout.item_add_leak) {

    override fun convert(holder: BaseViewHolder, item: ListInfo) {
        holder.run {
            val position = holder.layoutPosition + 1
            val start = item.s
            val end = item.e
            val startV: Float = start?.v ?: 0f
            val endV: Float = end?.v ?: 0f
            val time = "${start?.time?.substring(11)}~${end?.time?.substring(11)}"
            val value = (start?.mile ?: 0f) - (end?.mile ?: 0f)
            val valueKm = value / 1000.0
            val leak = ToolsUtil.formitNumberD("2", abs(endV - startV))
            setText(R.id.tvNumber, position.toString())
            setText(R.id.tvStartEndTime, time)
            setText(R.id.tvStartTotal, "$startV$unit")
            setText(R.id.tvEndTotal, "${end?.v}$unit")
            setText(R.id.tvAddLeakTotal, "$leak$unit")
            setText(R.id.tvRunMile, "${ToolsUtil.formitNumber("2", abs(valueKm))}${Units.km}")
        }
    }
}